
/******************************************************************************\
|    Title:        	 FIGUREF2: Share of Staffers Leaving to Become Lobbyists   |
|    Date:         	 July 2023	                                         	   |
|    Author:         Elisa Wirsching	      							       |
\******************************************************************************/


clear all
set more off, permanently
numlabel, add
set maxvar 32000

use congress_yearly.dta, clear

* create groups depending on coverage type
foreach x in treatment {
sort stafferid year
bysort stafferid: gen staycovered_`x' = (`x'==1 & `x'[_n-1]==1) if stafferid==stafferid[_n-1] & year==year[_n-1]+1
replace staycovered_`x'=. if `x'==. | `x'[_n-1]==.
bysort stafferid: gen stayuncovered_`x' = (`x'==0 & `x'[_n-1]==0) if stafferid==stafferid[_n-1] & year==year[_n-1]+1
replace stayuncovered_`x'=. if `x'==. | `x'[_n-1]==.
}

* different coverage groups
gen groupb = 1 if switchtouncovered_treatment == 1 // switch to uncovered
replace groupb = 2 if staycovered_treatment == 1 // stay covered
replace groupb = 3 if switchtocovered_treatment == 1 // switch to covered
replace groupb = 4 if (stayuncovered_treatment == 1 & percent_annualpay >=.70 & nonadmin_everyear==1) | (stayuncovered_treatment == 1 & percent_annualpay_exec >=.9 & nonadmin_everyear==0) // stay uncovered (above 70% for non-admin staff and 90% for admin staff)

* collapse to get share of direct revolvers by groups
collapse (mean) meanlobbydirectafter= lobbydirectafter (sd) sdlobbydirectafter=lobbydirectafter (count) n=lobbydirectafter, by(groupb posttreat)

generate hilobby = meanlobbydirectafter + invttail(n-1,0.025)*(sdlobbydirectafter / sqrt(n))
generate lowlobby = meanlobbydirectafter - invttail(n-1,0.025)*(sdlobbydirectafter / sqrt(n))

generate grouptreat = groupb    if posttreat == 0
replace  grouptreat = groupb+5  if posttreat == 1
sort grouptreat
list grouptreat posttreat groupb, sepby(posttreat)

* plot
twoway (bar meanlobbydirectafter grouptreat if groupb==1, color(gs3)) ///
       (bar meanlobbydirectafter grouptreat if groupb==2, color(gs6)) ///
       (bar meanlobbydirectafter grouptreat if groupb==3, color(gs11)) ///
       (bar meanlobbydirectafter grouptreat if groupb==4, color(gs13)) ///
       (rcap hilobby lowlobby grouptreat, lcolor(black)), ///
       text(0.005 1 "430" 0.005 2 "6679" 0.005 3 "2233" 0.005 4 "1896" 0.005 6 "796" 0.005 7 "14014" 0.005 8 "3829" 0.005 9 "3674", color(white) size(small)) graphregion(color(white)) ///
	   legend(row(2) order(1 "Switch to uncovered" 2 "Stay covered" 3 "Switch to covered" 4 "Stay uncovered (>70%)") ) ///
       xlabel( 2.5 "Pre reform" 7.5 "Post reform", noticks) ///
       xtitle("Types of staffers") ytitle("Average share of staff leaving to lobby") 



